<!--  项目终审列表 -->
<template>
  <RkContainer :isFooter="false"
    :isAside=false>
    <template #header_left>
      <RkButtonGroup :options="json_final_button"
        v-model="queryParams.wfStatus"
        @click="handleSearch" />
    </template>
    <template #header_right>
      <el-button v-if="queryParams.wfStatus=='001'"
        type="primary"
        @click="handleJudgment('audit', '终审')">终审</el-button>
      <el-button v-if="queryParams.wfStatus=='002'"
        type="danger"
        @click="handleOperation('back', '撤销')">撤销</el-button>
    </template>
    <template #main>
      <rk-condition>
        <template #content>
          <rk-grid ref="grProjApply"
            title="任务信息"
            dataUrl="/proResApply/reserveProjectPage"
            boxConfig
            :params="queryParams"
            :columns="tableColumns">
            <template #toolbar_title_buttons>
              <el-input v-model="queryParams.name"
                placeholder="请输入任务名称"
                class="mr-15px w-200px"
                clearable
                @click="handleSearch">
              </el-input>
            </template>
            <template #operation="{ row }">
              <div class="operation-box">
                <el-button type="primary"
                  link>设计</el-button>
                <el-button type="primary"
                  link>预览</el-button>
              </div>
            </template>
            <template #status="{ row }">
              <el-tag :type="COMMON_STOP_OPEN_ENUMS.options[row.status].tagType"
                class="mx-1"
                effect="plain">
                {{ COMMON_STOP_OPEN_ENUMS.options[row.status].echo }}
              </el-tag>
            </template>
          </rk-grid>
        </template>
      </rk-condition>
    </template>
  </RkContainer>
  <SpecialPriorityProjSortList ref="SpecialPriorityProjSortListRef" />
</template>
<script setup>
import { json_final_button } from '@/common/button-data.js'
import { COMMON_STOP_OPEN_ENUMS } from '@/enums/enums-common.js'
import SpecialPriorityProjSortList from '../drawer/SpecialPriorityProjSortList.vue'
import { useRoute } from 'vue-router'

const { appContext } = getCurrentInstance();
const globalProxy = appContext.config.globalProperties;
const grProjApply = ref('')
// 终审项目列表模板引用
const SpecialPriorityProjSortListRef = ref('')
// 查询参数
let queryParams = reactive({
  wfStatus: '001',
  mhcx: undefined,
  bondTypeCode: 1,    // 债券类型测试数据 1、一般 2、专项
  nodeId: undefined,  //填报测试数据
  processKey: 'PRO_CBK', //测试数据
  adCode: '2300', //
  agCode: undefined,
  agId: undefined,
  dw: 2
})
let route = useRoute()
queryParams.nodeId = route.query.nodeId

const tableColumns = ref([
  {field: 'agencyName', title: '任务名称', width: 250, align: 'left'},
  { field: 'fiscalYear1', title: '阶段', width: 120, align: 'center', },
  { field: 'applyDate', title: '创建日期', width: 120, align: 'center', },
  { field: 'startDate', title: '任务开始日期', width: 200, align: 'center' },
  { field: 'endDate', title: '任务结束日期', width: 200, align: 'center' },
  { field: 'totalBudget', title: '项目总数', width: 200, align: 'right' },
  { field: 'applyDate3', title: '评审报告', width: 200, align: 'right' },
  { field: 'applyDate4', title: '任务附件', width: 200, align: 'left' },
  { field: 'remark', title: '备注', width: 120, align: 'left' },
])
/**查询 */
const handleSearch = () => {
  grProjApply.value.searchEvent()
}
//送审、撤销送审
const handleOperation = async (buttonType, textName) => {
  const seleRows = grProjApply.value.getCheckboxRecords()
  if (seleRows.length == 0 || !seleRows) {
    globalProxy.$message({ message: `请至少选择一条数据进行${textName}！`, type: "warning" });
    return;
  }
  //获取选中数据
  const ProId = []
  const TaskId = []
  const ApplyId = []
  seleRows.forEach(element => {
    ApplyId.push(element.applyId)
    ProId.push(element.proId)
    TaskId.push(element.taskId)
  });
  const applyIds = ApplyId.join(',')
  const proIds = ProId.join(',')
  const taskIds = TaskId.join(',')
  if (buttonType == 'audit') { //送审
   } else if (buttonType == 'back') { //撤销送审
    const deleteParams = { applyIds, taskIds, proIds, nodeId: queryParams.nodeId, taskType: WF_TASK_CANCEL.value }
    // const result = await reserveProHandleTask(deleteParams)
    // const { data, code, msg } = result
    // if (code === 200) {
    //   globalProxy.$message({ message: `${textName}成功！`, type: "success" });
    //   handleSearch()
    // } else {
    //   globalProxy.$message({ message: `${msg}`, type: "error" });
    // }
  }
}

/**
 * 送审
 */
const handleJudgment = () => {
  SpecialPriorityProjSortListRef.value.handleEdit()
}


</script>
  
<style lang="scss" scoped>
.mr-15px {
  margin-right: 15px;
  &:last-child {
    margin-right: 0;
  }
}
.w-200px {
  width: 200px;
}
</style>
  